package com.bsc.rtc.lib.libraries.IjkPlayer;


import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import com.bsc.rtc.lib.libraries.IjkPlayer.media.AndroidMediaController;
import com.bsc.rtc.lib.libraries.IjkPlayer.media.IjkVideoView;
import com.bsc.rtc.lib.libraries.R;

import tv.danmaku.ijk.media.player.IjkMediaPlayer;

public class IjkDemoActivity extends AppCompatActivity {
    IjkVideoView videoView;

    AndroidMediaController mMediaController;
    ActionBar actionBar;
    boolean mBackPressed = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ijk_demo);
        // ButterKnife.bind(this);
        actionBar = getSupportActionBar();
        initView();
    }


    private void initView() {
        //这里使用的是Demo中提供的AndroidMediaController类控制播放相关操作
        mMediaController = new AndroidMediaController(this, false);
        mMediaController.setSupportActionBar(actionBar);
        videoView = findViewById(R.id.videoview);
        videoView.setMediaController(mMediaController);
        videoView.setVideoPath("http://stream1.grtn.cn/tvs2/sd/live.m3u8?_ts&time=1518428696629");
        videoView.start();

    }

    @Override
    public void onBackPressed() {
        mBackPressed = true;
        super.onBackPressed();
    }

    @Override
    protected void onStop() {
        super.onStop();
        //点击返回或不允许后台播放时 释放资源
        if (mBackPressed || !videoView.isBackgroundPlayEnabled()) {
            videoView.stopPlayback();
            videoView.release(true);
            videoView.stopBackgroundPlay();
        } else {
            videoView.enterBackground();
        }
        IjkMediaPlayer.native_profileEnd();
    }
}
